I want a single return statement instead of having a return statement in each if statement. Can anybody tell me how to do it?
public object GetHeaderInfo(string agentId, string headerName)
{
if (headerName =="flyer")
{
var headerInfo = Service.GetFlierHeaderInfo(agentId);
// headerinfo is of type Flier object
return headerInfo;
}
if (headerName == "general")
{
var headerInfo = Service.GetHeaderInfo(agentId);
// headerinfo is of type report object
return headerInfo;
}
return 0;
}
Anonymous User
13-Nov-2013Declare it at the top of your method :
The default value can be added during the initialization, it will be overwritten by any future assignation.